package com.psdi.element;

import com.psdi.Main;
import com.psdi.manager.GameLoader;
import com.psdi.physics.Collider;

import java.util.HashSet;
import java.util.Set;

/**
 * 爆炸类
 * 用于处理游戏中的爆炸效果
 */
public class Boom extends ElementObject implements Collider {
    public int num=0;
    public float animationTime=0.05f;
    public Boom(){}

    @Override
    public void update() {
        if (num == 17) {
            setAlive(false);
            GameLoader.LoadProp(this.transform.position);
            return;
        }
        num%=17;
        // 更新爆炸图片
        setImage(GameLoader.iconMap2.get(tag.toString()).get(num));
        animationTime -= Main.DELTA_TIME;
        if(animationTime <=0){
            animationTime = 0.05f;
            num++;
        }
    }

    public ElementObject CreateBoom(Position pos , Size size) {
        this.tag=Tag.BOOM;
        this.transform = new Transform(pos,new Rotation(),size);
        this.image = GameLoader.iconMap2.get(tag.toString()).get(0);
        return this;
    }

    @Override
    public Size colliderSize() {
        return transform.size;
    }

    @Override
    public Position colliderPosition() {
        return transform.position;
    }

    @Override
    public Tag colliderTag() {
        return tag;
    }

    @Override
    public Set<Tag> colliderFilterTag() {
        Set<Tag> set = new HashSet<>();
        set.add(Tag.MAP);
        set.add(Tag.ENEMY);
        return set;
    }

    @Override
    public void onCollisionStay(ElementObject other) {

    }
}
